package com.spa.infrastructure.mapper;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.spa.application.command.admin.MassagistAdminEditCommand;
import com.spa.application.command.massagist.MassagistMyEditCommand;
import com.spa.application.command.massagist.MassagistOnlineCommand;
import com.spa.application.command.shop.MassagistAddCommand;
import com.spa.application.command.shop.MassagistEditCommand;
import com.spa.application.dto.PageResult;
import com.spa.application.dto.admin.MassagistExportDTO;
import com.spa.application.dto.massagist.*;
import com.spa.application.dto.member.MemberMassagistDTO;
import com.spa.application.dto.member.MemberMassagistDetailsDTO;
import com.spa.application.dto.shop.ActualMassagistInfoDTO;
import com.spa.application.dto.shop.MassagistBaseInfoDTO;
import com.spa.application.dto.shop.ShopMassagistDetailsDTO;
import com.spa.application.query.admin.MassagitsPageQuery;
import com.spa.application.query.member.MemberMassagistCollectionQuery;
import com.spa.application.query.member.MemberMassagistDetailsQuery;
import com.spa.application.query.member.MemberMassagistQuery;
import com.spa.application.query.shop.MassagistListQuery;
import com.spa.domain.entity.MassageServiceEntity;
import com.spa.domain.entity.Massagist;
import com.spa.infrastructure.enums.dict.massagist.MassagistStatusEnum;
import com.spa.infrastructure.enums.dict.massagist.MassagistTagEnum;
import com.spa.infrastructure.enums.dict.massagist.MassagistTypeEnum;
import com.spa.infrastructure.repository.condition.MassagistCondition;
import com.spa.infrastructure.repository.po.MassagistPO;
import org.mapstruct.*;
import org.mapstruct.factory.Mappers;

import java.util.List;

@Mapper
@MapperConfig(unmappedTargetPolicy = ReportingPolicy.WARN)
public interface MassagistMapperStruct {

    MassagistMapperStruct INSTANCE = Mappers.getMapper(MassagistMapperStruct.class);

    MassagistPO command2Po(MassagistAddCommand command);

    @Mapping(source = "massagistId",target = "id")
    MassagistPO command2Po(MassagistEditCommand command);

    MassagistPO command2Po(MassagistAdminEditCommand command);

    Page<Massagist> po2Entity4Page(Page<MassagistPO> po);
    List<Massagist> po2Entity4List(List<MassagistPO> po);
    Massagist po2Entity(MassagistPO po);

    PageResult<MassagistBaseInfoDTO> entity2Dto4Page(Page<Massagist> entity);

    List<MemberMassagistDTO> entity2MemberDto4List(List<Massagist> entity);

    PageResult<MemberMassagistDTO> entity2MemberDto4Page(Page<Massagist> entity);

    @Mapping(source = "tag", target = "tag", qualifiedByName = "type2Enum")
    MassagistBaseInfoDTO entity2Dto(Massagist entity);

    MassagistFinanceDTO entity2FinanceDto(Massagist entity);

    MassagistPO editCommand2Po(MassagistMyEditCommand command);


    MassagistHomeDTO entity2HomeDto(Massagist entity);

    MemberMassagistDetailsDTO entity2MemberDto(Massagist entity);

    @Mapping(source = "tag", target = "tag", qualifiedByName = "type2Enum")
    ShopMassagistDetailsDTO entity2ShopDto(Massagist entity);

    MassagistCondition query2Condition(MemberMassagistQuery query);
    MassagistCondition query2Condition(MassagistListQuery query);
    MassagistCondition query2Condition(MemberMassagistDetailsQuery query);


    List<MassageServiceDTO> entity2DTO(List<MassageServiceEntity> entity);

    MassagistPO condition2PO(MassagistCondition condition);

    Massagist command2entity(MassagistOnlineCommand command);


    MassagistFinanceDetailBaseDTO Finance2FinanceBase(MassagistFinanceDetailDTO detailDTO);

    MassagistCondition pageQuery2condition(MassagitsPageQuery query);

    MassagistCondition queryMassagistCollection2Condition(MemberMassagistCollectionQuery query);

    MassagistFinanceDetailDTO dot2MassagistFinanceDetailDTO(MassagistIncomeDetailDTO massagistIncomeDetailDTO);

    @Mapping(source = "status", target = "status", qualifiedByName = "int2Enum")
    ActualMassagistInfoDTO entity2actualDto(Massagist entity);

    @Named("type2Enum")
    default MassagistTypeEnum type2Enum(int type) {
        return MassagistTypeEnum.byCode(type);
    }

    @Named("int2Enum")
    default MassagistStatusEnum int2Enum(int status) {
        return MassagistStatusEnum.byCode(status);
    }

    @Named("tag2Enum")
    default MassagistTagEnum tag2Enum(int type) {
        return MassagistTagEnum.byCode(type);
    }

    @Named("int2Str")
    default String int2Str(int type) {
        return MassagistTypeEnum.byCode(type).getDesc();
    }

    @Named("intTag2Str")
    default String intTag2Str(int type) {
        return MassagistTagEnum.byCode(type).getDesc();
    }

    List<MassagistExportDTO> dto2entity(List<Massagist> massagistList);
    @Mapping(source = "tag", target = "tag", qualifiedByName = "int2Str")
    @Mapping(source = "type", target = "type", qualifiedByName = "intTag2Str")
    MassagistExportDTO entity2ExportDto(Massagist massagist);
}
